<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      Object.defineProperty(obj,propName,{})
        - 主要是对一个已经存在的对象中的属性进行修改
      */

      /* const obj = {
        name: "laowang",
        age: 18,
      };

      //修改obj中的name属性的 特性
      Object.defineProperty(obj, "name", {
        value: "laowang",
        writable: false,
        enumerable: false,
        configurable: false,
      });

      obj.name = "lily";
      console.log(obj);

      //getter函数和setter函数(存取器属性)
      Object.defineProperty(obj, "age", {
        get() {
          console.log("获取值了");
          return 18;
        },
        set(newValue) {
          console.log("值更信息了");
        },
      });

      obj.age++; */




      /* 
      Object.defineProperty(obj,propName,{})
        - 主要是对一个已经存在的对象中的属性进行修改
      */

      const obj = {
        name: "老王",
        age: 18
      }

      //修改obj中name属性的特性
      /* Object.defineProperty(obj , "name" , {
        value: "老王",
        writable: true,
        enumerable: true,
        configurable: true,
      }) */

      //给obj中的age属性添加存取器
      Object.defineProperty(obj , "age" , {
        get(){
          console.log("获取值了");
          return 18;
        },
        set(newValue){
          console.log("值更新了");
        }
      })

      obj.age++

      /* //修改
      obj.name = "laowang"

      //枚举
      for (let key in obj){
        console.log(key);
      }

      //删除
      delete obj.name */

      console.log(obj , "obj");



    </script>
  </body>
</html>
